/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.User;

import Entities.Movie;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author Edwin
 */
public class MovieView extends javax.swing.JFrame {
    
    ImageIcon image;

    /**
     * Creates new form MovieView
     */
    public MovieView() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        labelCoverMovie = new javax.swing.JLabel();
        jLabelNameMovie = new javax.swing.JLabel();
        jLabelGenreMovie = new javax.swing.JLabel();
        jLabelYearMovie = new javax.swing.JLabel();
        jLabelDurationMovie = new javax.swing.JLabel();
        jLabelPlotKeywordsMovie = new javax.swing.JLabel();
        jLabelAvailableForPurchaseMovie = new javax.swing.JLabel();
        jLabelAvailableForRentalMovie = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        star1 = new javax.swing.JLabel();
        star2 = new javax.swing.JLabel();
        star3 = new javax.swing.JLabel();
        star4 = new javax.swing.JLabel();
        star5 = new javax.swing.JLabel();
        star6 = new javax.swing.JLabel();
        star7 = new javax.swing.JLabel();
        star8 = new javax.swing.JLabel();
        star9 = new javax.swing.JLabel();
        star10 = new javax.swing.JLabel();

        jMenuItem1.setText("jMenuItem1");

        jButton1.setText("OK!");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel1.setText("Rating:");

        star1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        star10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/EmptyStar.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelPlotKeywordsMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelAvailableForPurchaseMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelYearMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelDurationMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelGenreMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelNameMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelAvailableForRentalMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(labelCoverMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(144, 144, 144)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(164, 164, 164)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 22, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(star1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(star10)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(76, Short.MAX_VALUE)
                .addComponent(labelCoverMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelNameMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelGenreMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelDurationMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelYearMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabelAvailableForPurchaseMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelPlotKeywordsMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelAvailableForRentalMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(star1)
                        .addComponent(star3, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(star4)
                    .addComponent(star5)
                    .addComponent(star6)
                    .addComponent(star7)
                    .addComponent(star2)
                    .addComponent(star8)
                    .addComponent(star9)
                    .addComponent(star10))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        this.setVisible(false);
    }//GEN-LAST:event_jButton1MouseClicked

    /**
     * @param args the command line arguments
     */
    
    
    public void enterData(Movie movie){
        image = new ImageIcon (movie.getCover());
        System.out.println("Cover"+movie.getCover());
        
        this.jLabelNameMovie.setText(movie.getName());
        this.jLabelGenreMovie.setText(movie.getGenre());
        this.jLabelYearMovie.setText(""+movie.getYear());
        this.jLabelDurationMovie.setText(""+movie.getDuration());
        this.jLabelPlotKeywordsMovie.setText(movie.getPlotKeywords());
        this.jLabelAvailableForPurchaseMovie.setText(""+movie.getAvailableForPurchase());
        this.jLabelAvailableForRentalMovie.setText(""+movie.getAvailableForRental());
        
        
        ArrayList<JLabel> stars = new ArrayList<>();
        stars.add(star1);
        stars.add(star2);
        stars.add(star3);
        stars.add(star4);
        stars.add(star5);
        stars.add(star6);
        stars.add(star7);
        stars.add(star8);
        stars.add(star9);
        stars.add(star10);
        
        
        
        for(int i = 1; i<=movie.getRating().intValue(); i++){
            stars.get(i).setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/FullStar.png")));            
        }
        float x = (movie.getRating() - movie.getRating().intValue());
        if(!(x == 0)){
            stars.get(movie.getRating().intValue() + 1).setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/User/HalfStar.png")));            
        }
        
        
                
    }
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MovieView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MovieView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MovieView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MovieView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MovieView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelAvailableForPurchaseMovie;
    private javax.swing.JLabel jLabelAvailableForRentalMovie;
    private javax.swing.JLabel jLabelDurationMovie;
    private javax.swing.JLabel jLabelGenreMovie;
    private javax.swing.JLabel jLabelNameMovie;
    private javax.swing.JLabel jLabelPlotKeywordsMovie;
    private javax.swing.JLabel jLabelYearMovie;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JLabel labelCoverMovie;
    private javax.swing.JLabel star1;
    private javax.swing.JLabel star10;
    private javax.swing.JLabel star2;
    private javax.swing.JLabel star3;
    private javax.swing.JLabel star4;
    private javax.swing.JLabel star5;
    private javax.swing.JLabel star6;
    private javax.swing.JLabel star7;
    private javax.swing.JLabel star8;
    private javax.swing.JLabel star9;
    // End of variables declaration//GEN-END:variables
}
